package com.totoro.tymapping;

import com.totoro.tymapping.commands.MainCommand;
import com.totoro.tymapping.constants.CommandConst;
import com.totoro.tymapping.constants.StaticSystemVarConst;
import com.totoro.tymapping.listener.TyMappingListener;
import com.totoro.tymapping.manager.AttributeManager;
import com.totoro.tymapping.manager.CheckTaskManager;
import com.totoro.tymapping.manager.ConfigManager;
import com.totoro.tymapping.manager.LanguageManager;
import com.totoro.tymapping.utils.ColorUtil;
import org.bukkit.plugin.java.JavaPlugin;

/* @version 0.1.0
 * @author Totoro
 * @date: ${DATE} - ${TIME}
 * @description Spigot-启动类
 */
public final class TyMapping extends JavaPlugin {

    private static TyMapping INSTANCE;

    private ConfigManager configManager;

    private LanguageManager languageManager;

    private AttributeManager attributeManager;

    private CheckTaskManager checkTaskManager;

    @Override
    public void onEnable() {
        INSTANCE = this;
        getServer().getConsoleSender().sendMessage(StaticSystemVarConst.CONSOLE_PREFIX +
                ColorUtil.color("&f插件正在加载中..."));

        if(null == getServer().getPluginManager().getPlugin("PlaceholderAPI")) {
            StaticSystemVarConst.dependentPlaceholderAPIEnable = false;
            getServer().getConsoleSender().sendMessage(StaticSystemVarConst.CONSOLE_PREFIX +
                    ColorUtil.color("&c未找到依赖PlaceholderAPI，暂不启用PAPI变量解析"));
        }
        if(null == getServer().getPluginManager().getPlugin("AttributePlus")) {
            getServer().getConsoleSender().sendMessage(StaticSystemVarConst.CONSOLE_PREFIX +
                    ColorUtil.color("&c未找到依赖AttributePlus，无法使用AP作为属性源"));
        } else {
            getServer().getConsoleSender().sendMessage(StaticSystemVarConst.CONSOLE_PREFIX +
                    ColorUtil.color("&a已找到依赖AttributePlus，可启用AP作为属性源"));
        }
        if(null == getServer().getPluginManager().getPlugin("DragonCore")) {
            StaticSystemVarConst.dependentDragonCoreEnable = false;
            getServer().getConsoleSender().sendMessage(StaticSystemVarConst.CONSOLE_PREFIX +
                    ColorUtil.color("&c未找到依赖DragonCore，龙核槽位无法检测"));
        }
        this.configManager = new ConfigManager(this);
        this.languageManager = new LanguageManager(this);
        this.attributeManager = new AttributeManager(this);
        this.checkTaskManager = new CheckTaskManager(this);
        // 注册监听器
        TyMappingListener tyMappingListener = new TyMappingListener(this);
        getServer().getPluginManager().registerEvents(tyMappingListener, this);

        // 注册指令
        MainCommand mainCommand = new MainCommand(this);
        getCommand(CommandConst.COMMAND_NAME).setExecutor(mainCommand);
        getCommand(CommandConst.COMMAND_NAME).setTabCompleter(mainCommand);

        getServer().getConsoleSender().sendMessage(StaticSystemVarConst.CONSOLE_PREFIX +
                ColorUtil.color("&d插件加载完毕"));
    }

    @Override
    public void onDisable() {
        
        
    }

    public static TyMapping getInstance() {
        return INSTANCE;
    }

    public ConfigManager getConfigManager() {
        return configManager;
    }

    public LanguageManager getLanguageManager() {
        return languageManager;
    }

    public AttributeManager getAttributeManager() {
        return attributeManager;
    }

    public CheckTaskManager getCheckTaskManager() {
        return checkTaskManager;
    }
}
